package com.ec.edu.server.hello.handler.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ec.edu.common.constants.NettyMap;
import com.ec.edu.common.enums.MsgType;
import com.ec.edu.common.enums.RoomType;
import com.ec.edu.common.vo.MessageVo;
import com.ec.edu.server.hello.handler.RoomTypeHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 设备、心跳
 */
@Slf4j
@Service("noneRoomType")
public class NoneRoomTypeHandler implements RoomTypeHandler {
    @Override
    public void dealRoom(ChannelHandlerContext ctx, MsgType msgType, RoomType roomType, String jsonStr, String code) {
        switch (msgType) {
            //心跳 接收应答
            case HEAR:
                //启动客户端
            case DEVICE:
                MessageVo messageVo = JSON.parseObject(jsonStr, new TypeReference<MessageVo>(){});
                NettyMap.channelMap.put(messageVo.getClientId(), ctx.channel().id());
                break;
                default:
                    log.error("不能处理的消息：{}", jsonStr);
        }
    }
}
